package com.example.service;

import com.example.entity.chat.dto.OllamaRequest;
import com.example.entity.chat.dto.OllamaResponse;
import org.springframework.stereotype.Service;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;

@Service
public class OllamaService {
    private final WebClient webClient;

    public OllamaService(WebClient ollamaClient) {
        this.webClient = ollamaClient;
    }

    public Mono<String> generateResponse(String prompt) {
        OllamaRequest request = new OllamaRequest();
        request.setModel("deepseek-r1:1.5b");
        request.setPrompt(prompt);

        return webClient.post()
                .uri("/api/generate")
                .bodyValue(request)
                .retrieve()
                .bodyToMono(OllamaResponse.class)
                .map(OllamaResponse::getResponse);
    }
}
